# -*- coding: utf-8 -*-
"""
Created on Fri Nov  9 15:46:05 2012

@author: nico
"""

#from pybrain.structure import FeedForwardNetwork
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection
from pybrain.structure import RecurrentNetwork

import numpy as np
import math

n = RecurrentNetwork()
inLayer = LinearLayer(12, name='in')
hiddenLayer = SigmoidLayer(6,name='hidden')
outLayer = LinearLayer(3,name='out')
n.addInputModule(inLayer)
n.addModule(hiddenLayer)
n.addOutputModule(outLayer)

in_to_hidden = FullConnection(inLayer, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)
recurrent_connections=FullConnection(hiddenLayer,hiddenLayer)
recurrent_connections_2=FullConnection(outLayer,hiddenLayer)

n.addConnection(in_to_hidden)
n.addConnection(hidden_to_out)
n.addRecurrentConnection(recurrent_connections)
n.addRecurrentConnection(recurrent_connections_2)

n.sortModules()

n.activate([1, 2,3,4,5,6,7,8,9,11,12,13])

N=10000
obj_pos=np.random.rand(N,3)
torres_pos=np.random.rand(N,9)
dx1=(obj_pos[:,0]-torres_pos[:,0])
dy1=(obj_pos[:,1]-torres_pos[:,1])
dz1=(obj_pos[:,2]-torres_pos[:,2])

dx2=(obj_pos[:,0]-torres_pos[:,3])
dy2=(obj_pos[:,1]-torres_pos[:,4])
dz2=(obj_pos[:,2]-torres_pos[:,5])


dx3=(obj_pos[:,0]-torres_pos[:,6])
dy3=(obj_pos[:,1]-torres_pos[:,7])
dz3=(obj_pos[:,2]-torres_pos[:,8]) 

r1=np.sqrt(dx1*dx1+dy1*dy1+dz1*dz1)
r2=np.sqrt(dx2*dx2+dy2*dy2+dz2*dz2)
r3=np.sqrt(dx3*dx3+dy3*dy3+dz3*dz3)

entradas=np.zeros([N,12])
entradas[:,0:9]=torres_pos
entradas[:,9]=r1-r2
entradas[:,10]=r1-r3
entradas[:,11]=r2-r3


